package com.homwee.listMenu.util.view;

import android.content.Context;


import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.homwee.factory.R;
import com.homwee.listMenu.util.MenuItemData.onValueChange;
import com.homwee.listMenu.util.MenuItemView;

public class ItemProgressBar extends MenuItemView{
	RelativeLayout mImage;
	TextView mName;
	RelativeLayout mBar;
	TextView mValue;
	android.widget.LinearLayout.LayoutParams mParams;
	RelativeLayout layout;

	public ItemProgressBar(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public ItemProgressBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public ItemProgressBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		layout =(RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.menu_progressbar, null);
		this.addView(layout);
		mImage =(RelativeLayout) layout.findViewById(R.id.ItemImage);
		mName =(TextView) layout.findViewById(R.id.ItemName);
		mBar =(RelativeLayout) layout.findViewById(R.id.bar);
		mValue =(TextView) layout.findViewById(R.id.progressValue);
		mParams =(android.widget.LinearLayout.LayoutParams)mBar.getLayoutParams();
		mMenuData.setOnValueChange(new onValueChange() {
			
			public void valueChange(int value) {
				// TODO Auto-generated method stub
				if(mMenuData.mMaxValue -mMenuData.mMinValue !=0){
					mParams.width =(mMenuData.mInitValue-mMenuData.mMinValue)*156/(mMenuData.mMaxValue -mMenuData.mMinValue);
				}
				mBar.setLayoutParams(mParams);
				mValue.setText(""+mMenuData.mInitValue);
			}
		});
	}
	@Override
	public void update() {
		// TODO Auto-generated method stub
		if(mMenuData.isEnable){
			mName.setTextColor(Color.WHITE);
			mValue.setTextColor(Color.WHITE);
		}else{
			mName.setTextColor(Color.GRAY);
			mValue.setTextColor(Color.GRAY);
		}
		mImage.setBackgroundResource(mMenuData.mNameImage);
		mName.setText(mMenuData.mName);
		if(mMenuData.mMaxValue -mMenuData.mMinValue !=0){
			mParams.width =(mMenuData.mInitValue-mMenuData.mMinValue)*156/(mMenuData.mMaxValue -mMenuData.mMinValue);
		}
		mBar.setLayoutParams(mParams);
		mValue.setText(""+mMenuData.mInitValue);
	}
}